package RJZ.Rainbow.Protocol;

import RJZ.Rainbow.Service.OrderService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
@Component
public class OrderProtocol implements InitializingBean {
    @Autowired
    OrderService orderService;

    Map<String, Method> methodmap=new HashMap<>();
    public void work() throws NoSuchMethodException {
        Class clazz=orderService.getClass();
        Method tip=clazz.getMethod("Print", String.class, String.class);
        methodmap.put("111",orderService.getClass().getMethod("OrderInput",String.class));
        methodmap.put("112",tip);
        methodmap.put("113",tip);
        methodmap.put("114",tip);
        methodmap.put("115",tip);
        methodmap.put("116",tip);
        methodmap.put("117",tip);
        methodmap.put("121",orderService.getClass().getMethod("OrderOutput", String.class, String.class));
        methodmap.put("122",tip);
        methodmap.put("123",tip);
        methodmap.put("124",tip);
    }
    public void match(String cop,Object args[]) throws InvocationTargetException, IllegalAccessException {
        methodmap.get(cop).invoke(orderService,args);
    }


    @Override
    public void afterPropertiesSet() throws Exception {
        work();
    }
}
